package com.bnp.reporting.java8.lambda;

import java.util.*;

/**
 * Created by adib on 09/11/14.
 */
public class TraverseCollectionLambda {

    public static void main(String[] args) {

        List<String> names = new ArrayList<String>();
        names.add("Tanguy");
        names.add("HongFei");
        names.add("ZhiHei");
        names.add("Stephane");
        names.add("Prachi");
        names.add("adib");
        names.add("Nokuei");
        names.add("neeraj");

        Collections.sort(names);
        System.out.println("Simple sort:");

        /*for (String name: names){
            System.out.println(name);
        }*/

        names.forEach(str -> System.out.println(str));

        Collections.sort(names, new Comparator<String>() {
                    @Override
                    public int compare(String str1, String str2) {
                        return str1.compareToIgnoreCase(str2);
                    }
                }
        );

        System.out.println("\nSort with comparator:");
        for (String name: names){
            System.out.println(name);
        }

        System.out.println("\nTraverse with Iterator:");
        Iterator<String> iterator = names.iterator();
        while(iterator.hasNext())
            System.out.println(iterator.next());
    }


}
